<?php
!defined('BASE_PATH') && die('forbidden');

class core_helper_excel{
	
	public static function output($data,$name = 'output', $header = 1){
		
		header("Content-Type:application/vnd.ms-excel");
		header("Content-Disposition:filename=".$name.".xls");
		
		self::_output($data, $header);
	}

	public static function _output($data, $header = 1) {
		if($header){
			$keys = array_keys(current($data));
			array_unshift($data,$keys);
		}
		
		foreach($data as $k=>$v){
			foreach($v as $kk=>$vv){
				is_numeric($vv) && $v[$kk] = "'" . $vv;
			}
			$data[$k] = implode("\t", $v);
		}
		
		$data = implode("\n", $data);
		
		echo $data."\n";
	}
	
}

?>